home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Treccani Italiana Di Scienze Lettere Ed Arti
/
[Enciclopedia] Treccani Italiana di scienze lettere ed arti.iso
/
pc
/
data
/
xxi_appendice_dvd.swf
/
scripts
/
__Packages
/
StringUtils.as
< prev
Wrap
Text File
|
2007-11-08
|
14KB
|
432 lines
class StringUtils
{
static var BACKSLASH = String.fromCharCode(92);
static var APICE = String.fromCharCode(39);
static var DOPPIOAPICE = String.fromCharCode(34);
static var TABSPACE = " ";
static var IMAGE_URL = "";
static var USE_SUB_SUP_FONT = false;
static var mImageCounter = 0;
function StringUtils()
{
}
static function addSlashes(string)
{
var _loc3_ = "";
var _loc1_ = 0;
while(_loc1_ < string.length)
{
if(string.charAt(_loc1_) == StringUtils.BACKSLASH)
{
_loc3_ += StringUtils.BACKSLASH + StringUtils.BACKSLASH;
}
else if(string.charAt(_loc1_) == StringUtils.APICE)
{
_loc3_ += StringUtils.BACKSLASH + StringUtils.APICE;
}
else if(string.charAt(_loc1_) == StringUtils.DOPPIOAPICE)
{
_loc3_ += StringUtils.BACKSLASH + StringUtils.DOPPIOAPICE;
}
else
{
_loc3_ += string.charAt(_loc1_);
}
_loc1_ = _loc1_ + 1;
}
return _loc3_;
}
static function stripTrailingSpaces(string)
{
string;
string = StringUtils.replace(string,"\r","");
string = StringUtils.replace(string,"\n","");
string = StringUtils.replace(string,"\t","");
string = StringUtils.trim(string);
return string;
}
static function replace(s, arg_search, arg_replace)
{
StringUtils.string = s;
var _loc3_ = undefined;
var _loc1_ = "";
var _loc4_ = "";
var _loc5_ = "";
if(arg_search.length == 1)
{
return StringUtils.string.split(arg_search).join(arg_replace);
}
_loc3_ = StringUtils.string.indexOf(arg_search);
if(_loc3_ == -1)
{
return StringUtils.string;
}
_loc1_ = StringUtils.string;
do
{
_loc3_ = _loc1_.indexOf(arg_search);
_loc4_ = _loc1_.substring(0,_loc3_);
_loc1_ = _loc1_.substring(_loc3_ + arg_search.length);
_loc5_ += _loc4_ + arg_replace;
}
while(_loc1_.indexOf(arg_search) != -1);
_loc5_ += _loc1_;
return _loc5_;
}
static function trim(s)
{
StringUtils.string = s;
var _loc1_ = undefined;
var _loc3_ = undefined;
var _loc2_ = undefined;
_loc3_ = StringUtils.string.length;
_loc1_ = 0;
while(StringUtils.string.charAt(_loc1_) == " ")
{
_loc1_ = _loc1_ + 1;
}
if(_loc1_)
{
StringUtils.string = StringUtils.string.substr(_loc1_ + 1,_loc3_);
if(_loc1_ == _loc3_)
{
return StringUtils.string;
}
}
_loc2_ = StringUtils.string.length - 1;
while(StringUtils.string.charAt(_loc2_) == " ")
{
_loc2_ = _loc2_ - 1;
}
StringUtils.string = StringUtils.string.substr(1,_loc2_ + 1);
return StringUtils.string;
}
static function trimWhiteAndCr(s)
{
StringUtils.string = s;
var _loc1_ = undefined;
var _loc3_ = undefined;
var _loc2_ = undefined;
_loc3_ = StringUtils.string.length;
_loc1_ = 0;
while(StringUtils.string.charAt(_loc1_) == " " || StringUtils.string.charCodeAt(_loc1_) == 13 || StringUtils.string.charCodeAt(_loc1_) == 10)
{
_loc1_ = _loc1_ + 1;
}
if(_loc1_)
{
StringUtils.string = StringUtils.string.substr(_loc1_ + 1,_loc3_);
if(_loc1_ == _loc3_)
{
return StringUtils.string;
}
}
_loc2_ = StringUtils.string.length - 1;
while(StringUtils.string.charAt(_loc2_) == " " || StringUtils.string.charCodeAt(_loc1_) == 13 || StringUtils.string.charCodeAt(_loc1_) == 10)
{
_loc2_ = _loc2_ - 1;
}
StringUtils.string = StringUtils.string.substr(1,_loc2_ + 1);
return StringUtils.string;
}
static function formatUrl(url)
{
if(url.indexOf("ftp://") != -1 || url.indexOf("news://") != -1 || url.indexOf("https://") != -1)
{
return url;
}
if(url.indexOf("http://") == -1 && url.indexOf("www") == -1)
{
return "http://www." + url;
}
if(url.indexOf("http://") != -1 && url.indexOf("www") == -1)
{
return StringUtils.replace(url,"http://","http://www.");
}
if(url.indexOf("http://") == -1)
{
return "http://" + url;
}
}
static function HtmlFunction(inLabel)
{
var _loc1_ = inLabel;
StringUtils.mImageCounter = 0;
var _loc3_ = _loc1_.indexOf("<sup>") >= 0;
var _loc2_ = _loc1_.indexOf("<sub>") >= 0;
var _loc4_ = _loc1_.indexOf("<img ") >= 0;
if(_loc3_ || _loc2_ || _loc4_)
{
_loc1_ = StringUtils.subSupImgFromHTML(_loc1_,_loc3_,_loc2_,_loc4_);
if(_loc3_ && _loc1_.indexOf("#A|") >= 0)
{
_loc1_ = _loc1_.split("#A|").join("<span class=\"s_Superscript\">");
_loc1_ = _loc1_.split("|A#").join("</span>");
}
if(_loc2_ && _loc1_.indexOf("#P|") >= 0)
{
_loc1_ = _loc1_.split("#P|").join("<span class=\"s_Subscript\">");
_loc1_ = _loc1_.split("|P#").join("</span>");
}
}
if(StringUtils.USE_SUB_SUP_FONT)
{
_loc1_ = _loc1_.split("<b>").join("<span class=\"s_Bold\">");
_loc1_ = _loc1_.split("</b>").join("</span>");
}
return _loc1_;
}
static function subSupImgFromHTML(origHTML, haveSup, haveSub, haveImg)
{
var _loc1_ = new XML();
var _loc2_ = undefined;
_loc1_.parseXML(origHTML);
if(haveSup || haveSub)
{
StringUtils.switchChars(_loc1_);
}
if(StringUtils.IMAGE_URL.length > 0 && haveImg)
{
StringUtils.handleEmbeddedImage(_loc1_);
}
_loc2_ = _loc1_.toString();
return _loc2_;
}
static function subSupFromHTML(origHTML)
{
var _loc2_ = new XML();
var _loc1_ = "";
_loc2_.parseXML(origHTML);
StringUtils.switchChars(_loc2_);
_loc1_ = _loc2_.toString();
if(_loc1_.indexOf("#A|") >= 0)
{
_loc1_ = _loc1_.split("#A|").join("<span class=\"s_Superscript\">");
_loc1_ = _loc1_.split("|A#").join("</span>");
}
if(_loc1_.indexOf("#P|") >= 0)
{
_loc1_ = _loc1_.split("#P|").join("<span class=\"s_Subscript\">");
_loc1_ = _loc1_.split("|P#").join("</span>");
}
if(StringUtils.USE_SUB_SUP_FONT)
{
_loc1_ = _loc1_.split("<b>").join("<span class=\"s_Bold\">");
_loc1_ = _loc1_.split("</b>").join("</span>");
}
return _loc1_;
}
static function handleEmbeddedImage(node)
{
if(node.nodeName != null)
{
if(node.nodeName == "img")
{
StringUtils.mImageCounter = StringUtils.mImageCounter + 1;
var _loc4_ = node.attributes.src;
var _loc3_ = _loc4_.split("#");
node.attributes.src = StringUtils.IMAGE_URL + _loc3_[0];
node.attributes.width = parseInt(_loc3_[1]);
node.attributes.height = parseInt(_loc3_[2]);
}
}
var _loc1_ = node.firstChild;
while(_loc1_ != null)
{
StringUtils.handleEmbeddedImage(_loc1_);
_loc1_ = _loc1_.nextSibling;
}
}
static function switchChars(node)
{
var _loc2_ = "";
if(node.nodeName != null)
{
if(node.nodeName == "sup")
{
var _loc1_ = "";
if(StringUtils.USE_SUB_SUP_FONT)
{
_loc1_ = "#A|" + node.firstChild.nodeValue + "|A#";
}
else
{
var _loc7_ = node.firstChild.nodeValue.length;
var _loc9_ = node.firstChild.nodeValue;
var _loc4_ = 0;
while(_loc4_ < _loc7_)
{
_loc2_ = _loc9_.charAt(_loc4_);
switch(_loc2_)
{
case "0":
_loc1_ += "⁰";
break;
case "1":
_loc1_ += "┬╣";
break;
case "2":
_loc1_ += "┬▓";
break;
case "3":
_loc1_ += "┬│";
break;
case "4":
_loc1_ += "⁴";
break;
case "5":
_loc1_ += "⁵";
break;
case "6":
_loc1_ += "⁶";
break;
case "7":
_loc1_ += "⁷";
break;
case "8":
_loc1_ += "⁸";
break;
case "9":
_loc1_ += "⁹";
break;
case "+":
_loc1_ += "⁺";
break;
case "=":
_loc1_ += "⁼";
break;
case "(":
_loc1_ += "⁽";
break;
case ")":
_loc1_ += "⁾";
break;
case "n":
_loc1_ += "ⁿ";
break;
case "-":
case String.fromCharCode(8722):
_loc1_ += "⁻";
break;
default:
_loc1_ += "#A|" + _loc2_ + "|A#";
break;
}
_loc4_ = _loc4_ + 1;
}
}
node.firstChild.nodeValue = _loc1_;
}
else if(node.nodeName == "sub")
{
_loc1_ = "";
if(StringUtils.USE_SUB_SUP_FONT)
{
_loc1_ = "#P|" + node.firstChild.nodeValue + "|P#";
}
else
{
var _loc6_ = node.firstChild.nodeValue.length;
var _loc8_ = node.firstChild.nodeValue;
_loc4_ = 0;
while(_loc4_ < _loc6_)
{
_loc2_ = _loc8_.charAt(_loc4_);
switch(_loc2_)
{
case "0":
_loc1_ += "₀";
break;
case "1":
_loc1_ += "Γéü";
break;
case "2":
_loc1_ += "Γéé";
break;
case "3":
_loc1_ += "Γéâ";
break;
case "4":
_loc1_ += "Γéä";
break;
case "5":
_loc1_ += "Γéà";
break;
case "6":
_loc1_ += "Γéå";
break;
case "7":
_loc1_ += "Γéç";
break;
case "8":
_loc1_ += "Γéê";
break;
case "9":
_loc1_ += "Γéë";
break;
case "+":
_loc1_ += "Γéè";
break;
case "-":
_loc1_ += "Γéï";
break;
case "=":
_loc1_ += "Γéî";
break;
case "(":
_loc1_ += "Γéì";
break;
case ")":
_loc1_ += "₎";
break;
default:
_loc1_ += "#P|" + _loc2_ + "|P#";
}
_loc4_ = _loc4_ + 1;
}
}
node.firstChild.nodeValue = _loc1_;
}
}
var _loc3_ = node.firstChild;
while(_loc3_ != null)
{
StringUtils.switchChars(_loc3_);
_loc3_ = _loc3_.nextSibling;
}
}
static function TabToSpace(inTabNumber)
{
var _loc2_ = "";
var _loc1_ = 0;
while(_loc1_ < inTabNumber)
{
_loc2_ += StringUtils.TABSPACE;
_loc1_ = _loc1_ + 1;
}
return _loc2_;
}
static function HtmlToText(inHtml)
{
if(!_global.gHtmlRenderer)
{
_global.gHtmlRenderer = _root.createTextField("txt_globalhtmlRenderer",1,0,0,100,200);
_global.gHtmlRenderer.html = true;
_global.gHtmlRenderer._visible = false;
_global.gHtmlRenderer.multiline = true;
}
_global.gHtmlRenderer.htmlText = inHtml;
return _global.gHtmlRenderer.text;
}
static function StripExt(inFilename)
{
var _loc1_ = inFilename.lastIndexOf(".");
if(_loc1_ >= 0)
{
return inFilename.substring(0,_loc1_);
}
return inFilename;
}
}